(both-times
 '(def (nif-expand args)
      (=>> (.chop args 2)
           (map (lambda (x) (if (= (length x) 2) x (cons 'else x))))))

 (def (nif-expand args #!optional stx)
      (if-let-list ((test then . args*) args)
                   (cons (list test then) (nif-expand args* stx))
                   (if-let-list ((els) args)
                                (list (list 'else els))
                                (raise-source-error stx "missing else branch")))))

(TEST
 > (nif-expand '(a "yes" b "no" "none"))
 ((a "yes") (b "no") (else "none"))
 > (%try-error (nif-expand '(a "yes" b "no")))
 [source-error "missing else branch"])


(defmacro (nif . args)
  (cons 'cond (nif-expand args stx)))

(defmacro (nif . args)
  (cons 'cond
        (let nif-expand ((args args))
          (if-let-list ((test then . args*) args)
                       (cons (list test then) (nif-expand args*))
                       (if-let-list ((els) args)
                                    (list (list 'else els))
                                    (raise-source-error stx "missing else branch"))))))

(TEST
 > (expansion#nif a "yes" b "no" "none")
 (cond (a "yes") (b "no") (else "none")))


;;(def (m a b) (* a b))
;;(begin (step) (+ 10 (m 20 2)))

(TEST
 > (def (t a b c)
        (nif a "a" b "b" c "c" "none"))
 > (t #f #f #f)
 "none"
 > (t #f #f #t)
 "c"
 > (t #t #f #t)
 "a"
 > (t #t #t #t)
 "a"
 > (t #f #t #t)
 "b")

'(def (t2 a b c)
     (nif a "a" b "b" c "c"))

